package com.yuhong.reggie.controller;

import com.yuhong.reggie.common.R;
import com.yuhong.reggie.dto.SetmealDto;
import com.yuhong.reggie.entity.Page;
import com.yuhong.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("/setmeal")
@RestController
public class SetmealCotroller {
    @Autowired(required = false)
    private SetmealService setmealService;
    //删除
    @DeleteMapping
    public R<String> deleteByIds(@RequestParam List<Long> ids, HttpSession session){
        Long employee = (Long) session.getAttribute("employee");

        setmealService.deleteByIds(ids,employee);
        return R.success("删除ok");
    }
    //分页查询
    @GetMapping ("/page")
    public R<Page<SetmealDto>> findBypage(Integer page,Integer pageSize,String name){
        Page<SetmealDto> setmealPage = setmealService.findByPage(page, pageSize, name);
        return R.success(setmealPage);
    }

    //新增套餐
    @PostMapping
    public R<String> save(@RequestBody SetmealDto setmealDto, HttpSession session){
        Long employee = (Long) session.getAttribute("employee");

        setmealDto.setCreateUser(employee);
        setmealDto.setUpdateUser(employee);

        setmealService.save(setmealDto);

        return R.success("添加套餐成功");
    }
}
